<template>
  <div class="app-container">
    <div class="search-bar">
      <el-form ref="form" :model="searchData" label-width="80px" size="mini">
        <el-row :gutter="10">
          <el-col :span="3.5">
            <el-form-item label="作业区">
              <el-select
                v-model="searchData.alarm_area"
                clearable
                placeholder="请选择作业区"
                style="width: 130px"
              >
                <el-option
                  v-for="(item, i) in opeArea"
                  :key="i"
                  :label="item"
                  :value="item"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3.5">
            <el-form-item label="预警状态">
              <el-select
                v-model="searchData.alarm_class"
                clearable
                placeholder="请选择预警状态"
                style="width: 130px"
              >
                <el-option label="超周期预警" value="0" />
                <el-option label="载荷差一级预警" value="1" />
                <el-option label="载荷差二级预警" value="2" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3.5">
            <el-form-item label="起始日期">
              <el-date-picker
                v-model="searchData.start_time"
                type="date"
                placeholder="选择日期"
                style="width: 130px"
                value-format="yyyy-MM-dd"
              />
            </el-form-item>
          </el-col>
          <el-col :span="3.5">
            <el-form-item label="截止日期">
              <el-date-picker
                v-model="searchData.end_time"
                type="date"
                placeholder="选择日期"
                style="width: 130px"
                value-format="yyyy-MM-dd"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="">
              <el-button
                type="primary"
                size="mini"
                @click="search"
              >查 询</el-button>
              <el-button size="mini" @click="reset">清 空</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="content">
      <el-table
        :data="tableData"
        border
        height="900"
        :header-cell-style="{height:'30px',padding:'0px',fontSize:'14px'}"
        style="width: 100%;font-size: 13px"
        :row-style="{height:'20px'}"
        :cell-style="{padding:'1px'}">
        <el-table-column type="index" width="50" fixed/>
        <el-table-column
          fixed
          prop="alarm_wellname"
          label="井号"
          sortable
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_area"
          label="单位"
          sortable
          width="120px"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_date"
          label="日期"
          width="120px"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_org"
          label="站号"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_block"
          label="区块"
          width="140px"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_strata"
          label="层位"
          header-align="center"
          align="center"
        />
        <el-table-column label="生产情况" header-align="center">
          <el-table-column
            prop="alarm_fluidvolume"
            label="液量"
            sortable
            header-align="center"
            align="center"
          />
          <el-table-column
            prop="alarm_oilvolume"
            label="油量"
            sortable
            header-align="center"
            align="center"
          />
          <el-table-column
            prop="alarm_watervolume"
            label="含水"
            sortable
            header-align="center"
            align="center"
          />
        </el-table-column>
        <el-table-column
          prop="alarm_pumpdepth"
          label="泵挂深度"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_cleancycle"
          label="清蜡周期"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_craft"
          label="清蜡工艺"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{
              scope.row.alarm_craft == '1'
                ? '热洗'
                : scope.row.alarm_craft == '2'
                  ? '化防'
                  : scope.row.alarm_craft == '3'
                    ? '化防+热洗'
                    : '冷洗'
            }}
          </template>
        </el-table-column>
        <el-table-column
          prop="alarm_hotwashamount"
          label="热洗用液"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_reason"
          label="预警原因"
          width="120px"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_continuedays"
          label="已持续预警天数"
          header-align="center"
          align="center"
        />
        <el-table-column label="作业区" header-align="center">
          <el-table-column
            prop="alarm_judgeresult"
            label="判断结果"
            header-align="center"
            align="center"
          />
          <el-table-column
            prop="alarm_nextwork"
            label="下步工作"
            header-align="center"
            align="center"
          />
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center">
          <template slot-scope="scope">
            <el-link
              type="primary"
              size="mini"
              @click="input(scope.row)"
            >录入</el-link>
          </template>
        </el-table-column>
      </el-table>
      <Pagination
        :page.sync="page"
        :limit.sync="limit"
        :total="total"
        @changePage="getListPage1(arguments)"
        @size-change="handleSizeChange"
      />
    </div>
    <el-dialog title="录入" :visible.sync="showInput" fullscreen>
      <el-form
        ref="inputForm"
        :model="inputForm"
        :rules="rules"
        label-width="200px"
      >
        <el-row :gutter="30">
          <el-col :span="6">
            <el-form-item label="井号">
              <el-input v-model="inputForm.alarm_wellname" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="单位">
              <el-input v-model="inputForm.alarm_area" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="站号">
              <el-input v-model="inputForm.alarm_org" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="区块">
              <el-input v-model="inputForm.alarm_block" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="层位">
              <el-input v-model="inputForm.alarm_strata" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="液量">
              <el-input v-model="inputForm.alarm_fluidvolume" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="油量">
              <el-input v-model="inputForm.alarm_oilvolume" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="含水">
              <el-input v-model="inputForm.alarm_watervolume" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="泵挂深度">
              <el-input v-model="inputForm.alarm_pumpdepth" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="清蜡周期">
              <el-input v-model="inputForm.alarm_cleancycle" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="清蜡工艺">
              <el-select v-model="inputForm.alarm_craft" disabled>
                <el-option label="热洗" value="1" />
                <el-option label="化防" value="2" />
                <el-option label="化防+热洗" value="3" />
                <el-option label="冷洗" value="4" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="热洗用液">
              <el-input v-model="inputForm.alarm_hotwashamount" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预警原因">
              <el-input v-model="inputForm.alarm_reason" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="已持续预警天数">
              <el-input v-model="inputForm.alarm_continuedays" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="判断结果" prop="alarm_judgeresult">
              <el-select v-model="inputForm.alarm_judgeresult">
                <el-option label="是" value="是" />
                <el-option label="否" value="否" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="下步工作" prop="alarm_nextwork">
              <el-input
                v-model="inputForm.alarm_nextwork"
                type="textarea"
                :rows="2"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="submit">提 交</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import Pagination from '@/components/pagination.vue'
export default {
  components: { Pagination },
  data() {
    return {
      searchData: {
        alarm_class_array: ['0','1','2'],
        alarm_cyclestate: '0'
      },
      tableData: [],
      opeArea:['第一采油作业区','第二采油作业区', '第三采油作业区','第五采油作业区','第七采油作业区','第八采油作业区','第九采油作业区','运行维护一中心'],
      page: 1,
      limit: 50,
      total: 0,
      showInput: false,
      inputForm: {},
      rules: {
        alarm_judgeresult: {
          required: true,
          message: '请输入判断结果',
          trigger: 'blur'
        },
        alarm_nextwork: {
          required: true,
          message: '请输入下步工作',
          trigger: 'blur'
        }
      }
    }
  },
  created() {
    this.getListPage(this.page, this.limit, this.searchData)
  },
  methods: {
    getListPage(pageNum, pageSize, data) {
      this.$http
        .post('/TAlarmWell/pageQuery', {
          pageNum,
          pageSize,
          data
        })
        .then(({ data: { data: res }}) => {
          this.tableData = res.records
          this.total = res.total
        })
        .catch((err) => {
          this.$message.error(err)
        })
    },
    //页码变动
    getListPage1(msg){
      let pageNum=msg[0]
      let pageSize=msg[1]
      let data=this.searchData
      this.$http.post('/TAlarmWell/pageQuery', { pageSize, pageNum, data }).then(({ data: { data: res }}) => {
        this.tableData = res.records
        this.total = res.total
      })
    },
    //每页记录数变动
    handleSizeChange(size){
      let pageSize=this.page
      let pageNum=size
      let data=this.searchData
      this.$http.post('/TAlarmWell/pageQuery', { pageSize, pageNum, data }).then(({ data: { data: res }}) => {
        this.tableData = res.records
        this.total = res.total
      })
    },
    changePage(pageNum, pageSize) {
      this.getListPage(pageNum, pageSize, this.searchData)
    },
    search() {
      this.page = 1
      this.getListPage(this.page, this.limit, this.searchData)
    },
    reset() {
      this.searchData = {}
    },
    input(data) {
      this.showInput = true
      this.inputForm = data
    },
    close() {
      this.showInput = false
    },
    submit() {
      this.$refs.inputForm.validate((valid) => {
        if (valid) {
          this.$http
            .post('/TAlarmWell/pageQuery', {
              id: this.inputForm.alarm_id,
              alarm_judgeresult: this.inputForm.alarm_judgeresult,
              alarm_nextwork: this.inputForm.alarm_nextwork
            })
            .then(() => {
              this.showInput = false
              this.inputForm = {}
            })
            .catch((err) => {
              this.$message.error(err)
              this.showInput = false
            })
        }
      })
    }
  }
}
</script>

<style scoped>
</style>
